﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace ZEFIT
{
    class MYSQLAdabterCustomer : Adabter
    {
        public override List<object> Select()
        {
            String conString = "SELECT ID, Name, Adresse, PLZ, Land FROM tbl_kunde;";
            List<object> reader = MYSQLConnecter.SelectRows(new MySqlCommand(conString));
            return reader;
        }

        public override void Insert(ref Data data)
        {
            Customer customer = (Customer)data;

            String conString = "INSERT INTO tbl_kunde (Name, Adresse, PLZ, Land) VALUES" +
                " ('" + customer.Name + "', '" + customer.Adress + "', " + customer.ZIP + ", '" + customer.Country + "');";
            customer.Id = MYSQLConnecter.SendInsert(new MySqlCommand(conString));

        }

        public override void Update(Data data)
        {
            Customer customer = (Customer)data;

            String conString = "UPDATE tbl_kunde" +
                " SET Name = '" + customer.Name + "', Adresse = '" + customer.Adress + "', PLZ = " + customer.ZIP + ", Land = '" + customer.Country + "'" +
                " WHERE ID = " + customer.Id + ";";
            MYSQLConnecter.Send(new MySqlCommand(conString));
        }

        public override void Delete(int id)
        {
            String conString = "DELETE FROM tbl_kunde" +
                " WHERE ID = " + id + ";";
            MYSQLConnecter.Send(new MySqlCommand(conString));
        }
    }
}
